// MIT License
//
// Copyright (c) 2023-Present - Violet Hansen - (aka HotCakeX on GitHub) - Email Address: spynetgirl@outlook.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// See here for more information: https://github.com/HotCakeX/Harden-Windows-Security/blob/main/LICENSE
//

using System.Runtime.InteropServices;

#pragma warning disable CS0649

namespace CommonCore.Interop;

internal enum IMAGE_MITIGATION_POLICY : uint
{
	ImageDepPolicy,
	ImageAslrPolicy,
	ImageDynamicCodePolicy,
	ImageStrictHandleCheckPolicy,
	ImageSystemCallDisablePolicy,
	ImageMitigationOptionsMask,
	ImageExtensionPointDisablePolicy,
	ImageControlFlowGuardPolicy,
	ImageSignaturePolicy,
	ImageFontDisablePolicy,
	ImageImageLoadPolicy,
	ImagePayloadRestrictionPolicy,
	ImageChildProcessPolicy,
	ImageSehopPolicy,
	ImageHeapPolicy,
	ImageUserShadowStackPolicy,
	MaxImageMitigationPolicy,
}

internal enum RTL_IMAGE_MITIGATION_OPTION_STATE : uint
{
	RtlMitigationOptionStateNotConfigured = 0,
	RtlMitigationOptionStateOn = 1,
	RtlMitigationOptionStateOff = 2,
	RtlMitigationOptionStateForce = 4,
	RtlMitigationOptionStateOption = 8,
}

internal struct RTL_IMAGE_MITIGATION_POLICY
{
	internal ulong PolicyState;
}

internal struct RTL_IMAGE_MITIGATION_ASLR_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY ForceRelocateImages;
	internal RTL_IMAGE_MITIGATION_POLICY BottomUpRandomization;
	internal RTL_IMAGE_MITIGATION_POLICY HighEntropyRandomization;
}

internal struct RTL_IMAGE_MITIGATION_DEP_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY Dep;
}

internal struct RTL_IMAGE_MITIGATION_STRICT_HANDLE_CHECK_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY StrictHandleChecks;
}

internal struct RTL_IMAGE_MITIGATION_SYSTEM_CALL_DISABLE_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY BlockWin32kSystemCalls;
	internal RTL_IMAGE_MITIGATION_POLICY BlockFsctlSystemCalls;
}

internal struct RTL_IMAGE_MITIGATION_EXTENSION_POINT_DISABLE_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY DisableExtensionPoints;
}

internal struct RTL_IMAGE_MITIGATION_DYNAMIC_CODE_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY BlockDynamicCode;
}

internal struct RTL_IMAGE_MITIGATION_CONTROL_FLOW_GUARD_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY ControlFlowGuard;
	internal RTL_IMAGE_MITIGATION_POLICY StrictControlFlowGuard;
}

internal struct RTL_IMAGE_MITIGATION_BINARY_SIGNATURE_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY BlockNonMicrosoftSignedBinaries;
	internal RTL_IMAGE_MITIGATION_POLICY EnforceSigningOnModuleDependencies;
}

internal struct RTL_IMAGE_MITIGATION_FONT_DISABLE_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY DisableNonSystemFonts;
}

internal struct RTL_IMAGE_MITIGATION_IMAGE_LOAD_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY BlockRemoteImageLoads;
	internal RTL_IMAGE_MITIGATION_POLICY BlockLowLabelImageLoads;
	internal RTL_IMAGE_MITIGATION_POLICY PreferSystem32;
}

[StructLayout(LayoutKind.Sequential)]
internal unsafe struct RTL_IMAGE_MITIGATION_PAYLOAD_RESTRICTION_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY EnableExportAddressFilter;
	internal RTL_IMAGE_MITIGATION_POLICY EnableExportAddressFilterPlus;
	internal RTL_IMAGE_MITIGATION_POLICY EnableImportAddressFilter;
	internal RTL_IMAGE_MITIGATION_POLICY EnableRopStackPivot;
	internal RTL_IMAGE_MITIGATION_POLICY EnableRopCallerCheck;
	internal RTL_IMAGE_MITIGATION_POLICY EnableRopSimExec;
	internal fixed char ModuleList[512]; // Null-terminated UTF-16 sequence (EAF/EAF+ module list)
}

internal struct RTL_IMAGE_MITIGATION_SEHOP_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY Sehop;
}

internal struct RTL_IMAGE_MITIGATION_HEAP_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY TerminateOnHeapErrors;
}

internal struct RTL_IMAGE_MITIGATION_CHILD_PROCESS_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY DisallowChildProcessCreation;
}

internal struct RTL_IMAGE_MITIGATION_USER_SHADOW_STACK_POLICY
{
	internal RTL_IMAGE_MITIGATION_POLICY UserShadowStack;
	internal RTL_IMAGE_MITIGATION_POLICY SetContextIpValidation;
	internal RTL_IMAGE_MITIGATION_POLICY BlockNonCetBinaries;
}
